/**
 * Created by zzy on 2017/10/23.
 */
import React, {Component} from 'react';
import {
    Text,
    View,
    TouchableOpacity,
    TextInput
} from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons'
import RequestUtil from "../util/NetRequest";
import meInfoStore from '../../luojs/store/MeInfoStore'

export default class SetNickName extends Component{
    static navigationOptions = {
        header: ()=>{
            return  null
        }
    };
    constructor(props){
        super(props);
        this.state=
            {
                text:meInfoStore.userName
            }

    }
    render(){
        return <View style={{flex:1,backgroundColor:'#f5f5f5'}}>
              <View style={{flexDirection:'row',alignItems:'center',justifyContent:'space-between',backgroundColor: 'white'}}>
                  <TouchableOpacity activeOpacity={1}
                                    onPress={()=>{
                                        this.props.navigation.goBack()
                                    }}>
                      <Ionicons name="ios-arrow-back" size={30} style={{padding:10}}/>
                  </TouchableOpacity>
                  <Text style={{fontSize:17}}>设置名字</Text>
                  <Text style={{padding:10}} onPress={this.setName.bind(this)}>完成</Text>
              </View>
            <TextInput style={{height: 40, backgroundColor: 'white',marginTop:20}}
                       onChangeText={(text) => this.setState({text})}
                       value={this.state.text}
                       underlineColorAndroid="transparent"
            />
        </View>
    }
    setName(){
        if(this.state.text=='')return;
        let param={
            nickName:this.state.text
        };
        RequestUtil.setNickName(param).then((data)=>{
            LOG('设置昵称--------'+JSON.stringify(data));
            meInfoStore.userName=this.state.text;
            this.props.navigation.goBack()
        })
    }
}